#define _CRT_SECURE_NO_WARNINGS 1

#include<iostream>
#include<vector>

using namespace std;

vector<int> canSeePersonsCount(vector<int>& heights) {
    int n = heights.size();
    vector<int> stk;
    vector<int> res(n, 0);

    for (int i = n - 1; i >= 0; i--)
    {
        int h = heights[i];
        while (!stk.empty() && stk.back() < h)
        {
            stk.pop_back();
            res[i] += 1;
        }
        if (!stk.empty())
            res[i] += 1;
        stk.push_back(h);
    }
    return res;
}

int main()
{
    vector<int> v = { 10,6,8,5,11,9 };
    canSeePersonsCount(v);
    return 0;
}